#include"process.h"
#include<unistd.h>
#include<time.h>
#include<stdlib.h>
double total = 1024.0;
//double speed = 1.0;
double speed[] = {10.0,0.001,0.002,0.003,0.004,0.012,0.031};
typedef void (*call_t)(const char*,double,double);
void download(int total,call_t cb)
{
  srand(time(0));
  double current = 0.0;
  while(current <= total)
  {
    int random = rand() % 7;
    cb("下载中",total,current);
    usleep(5000);
    if(current == total) break;
    current += speed[random];
    if(current >= total) current = total;
  }
}
void upload(int total,call_t cb)
{
  srand(time(0));
  double current = 0.0;
  while(current <= total)
  {
    int random = rand() % 7;
    cb("上传中",total,current);
    usleep(5000);
    if(current == total) break;
    current += speed[random];
    if(current >= total) current = total;
  }
}
int main()
{
  download(1024.0,Flushprocess);
  printf("1024MB下载完毕\n");
  download(512.0,Flushprocess);
  printf("512MB下载完毕\n");
  download(256.0,Flushprocess);
  printf("256MB下载完毕\n");
  download(128.0,Flushprocess);
  printf("128MB下载完毕\n");
  upload(2048.0,Flushprocess);
  printf("2048MB上传成功\n");
  //process();
  return 0;
}
